package com.itouchtv.yang.core.tools;

import com.itouchtv.yang.core.driver.CommDriver;

import java.io.File;
import java.io.IOException;

public class UpLoadPic {

    public static void upload(String file) {

        String path = ClassPath.getClassPath();

        Log.logger.info("自动选择文件上传:" + file);
        File file1 = new File(file);
        String filePath = file1.getAbsolutePath();
        File file2 = new File(path+"/autoIt/upload.exe");
        String executeFile = file2.getAbsolutePath(); //定义了upload.exe文件的路径
        System.out.println(executeFile);
        System.out.println(filePath);
        String borwser = CommDriver.driver.get().getDriverName();
        String cmd = "\"" + executeFile + "\"" + " " + "\"" + borwser.toUpperCase() + "\"" + " " + "\"" + filePath + "\"";
        System.out.println(cmd);
        Runtime runtime = Runtime.getRuntime();
        try {
            runtime.exec(cmd);
        } catch (IOException e) {
            Log.logger.error("运行 autoIt失败"+"\n"+e.fillInStackTrace());
            e.printStackTrace();
        }
        try {
            Log.logger.info("上传文件后等待5000ms");
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
